//
//  EndLiveViewController.m
//  penzer
//
//  Created by caiyc on 2018/9/26.
//  Copyright © 2018年 caiyc. All rights reserved.
//

#import "EndLiveViewController.h"

@interface EndLiveViewController ()
@property(nonatomic,strong)UIView *hostInfoView;
@end

@implementation EndLiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setViews];
    [self bindHostInfo];
    [self loadrInfo];
    // Do any additional setup after loading the view from its nib.
}
#pragma mark 加在直播的结束数据
-(void)loadrInfo{
    NSDictionary *param = @{@"ctrl":@"live_anchor",@"ac":@"member",@"ta":@"actdata",@"act_id":self.live_Id,@"op":@"member"};
    [self weqPostHandle:param success:^(id response) {
        if(response){
            
            NSDictionary *datas = response[@"data"];
            self.total_Num.text = [NSString stringWithFormat:@"%@元",datas[@"act_price"]];
            self.Add_Fasn.text = [NSString stringWithFormat:@"%@个",datas[@"news_fans"]];
            self.yinliu.text =  [NSString stringWithFormat:@"%@人",datas[@"man_num"]];
            self.saleNum.text =  [NSString stringWithFormat:@"%@件",datas[@"seal_num"]];
            self.time_Length.text =  [NSString stringWithFormat:@"%.2f分钟",[datas[@"live_lenght"]floatValue]/60];
            self.profie_Num.text = [NSString stringWithFormat:@"%@元",datas[@"anchor_money"]];
          //  self.total_Num.text = [NSString stringWithFormat:@"%@元",datas[@""]];
            NSString *starts = [XTool timeFrommartTotimeintral:datas[@"time"]];
            self.time_start.text = [NSString stringWithFormat:@"时间：%@",starts];
            NSArray *goods=datas[@"goods_list"];
            CGFloat startY = self.des_View.frame.size.height+self.des_View.frame.origin.y+10;
            for(int i =0;i<goods.count;i++){
                NSDictionary *goodInfo = goods[i];
                UIView *goodsView = [[UIView alloc]initWithFrame:CGRectMake(10, startY+100*i, screen_width-20, 100)];
                goodsView.backgroundColor = [UIColor whiteColor];
                goodsView.layer.cornerRadius = 5;
                UIImageView *imags = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 80, 80)];
                NSURL *url = [NSURL URLWithString:goods[i][@"thumb"]];
                [imags sd_setImageWithURL:url];
                UILabel *name = [[UILabel alloc]initWithFrame:CGRectMake(100, 10, screen_width-120, 30)];
                name.text = goodInfo[@"title"];
                name.font = [UIFont systemFontOfSize:15];
                name.textColor = [UIColor blackColor];
                UILabel *desc = [[UILabel alloc]initWithFrame:CGRectMake(100, 40, screen_width-120, 30)];
                desc.text = [goodInfo[@"content"]isEqualToString:@""]?@"暂无":goodInfo[@"content"];
                desc.font = [UIFont systemFontOfSize:13];
                desc.textColor = [UIColor blackColor];
                UILabel *price = [[UILabel alloc]initWithFrame:CGRectMake(100, 70, screen_width-120, 30)];
                price.text = goodInfo[@"buy_price"];
                price.font = [UIFont systemFontOfSize:18];
                price.textColor = [UIColor blackColor];
                [goodsView addSubview:imags];
                [goodsView addSubview:name];
                [goodsView addSubview:desc];
                [goodsView addSubview:price];
              
                [self.botom_ScroViews addSubview:goodsView];
            }
            self.botom_ScroViews.contentSize = CGSizeMake(0, startY+120*goods.count);
            
        }
    } failure:^(NSError *error) {
        
    }];
}
-(void)setViews{
    self.botom_ScroViews.contentSize = CGSizeMake(screen_width, screen_height*1.2);
    self.botom_View.layer.cornerRadius = 23;
    self.botom_View.layer.masksToBounds = 1;
    self.botom_View.alpha = .8;
    
    self.des_View.layer.cornerRadius= 5;
    self.des_View.layer.masksToBounds = 1;
    
    self.sale_Type.layer.cornerRadius = 16;
    self.sale_Type.layer.masksToBounds = 1;
    
    self.back_btn.layer.cornerRadius = 25;
    self.back_btn.layer.masksToBounds = 1;
    
    self.goods_View.layer.cornerRadius = 5;
    self.goods_View.layer.masksToBounds = 1;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (IBAction)finish:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:1];
}
- (IBAction)backs:(UIButton *)sender {
    [self.navigationController popToRootViewControllerAnimated:0];
}
-(UIView *)hostInfoView{
    if(!_hostInfoView){
        NSInteger margin_Top = KISIphoneX?55:30;
        //顶部主播简介
        _hostInfoView = [[UIView alloc] init];
        _hostInfoView.frame = CGRectMake(screen_width-176-30, margin_Top+20,176,40);
        _hostInfoView.layer.backgroundColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:0.6].CGColor;
        _hostInfoView.layer.cornerRadius = 20;
    }
    return _hostInfoView;
}
//绑定主播信息
-(void)bindHostInfo{
    
    [self.botom_ScroViews addSubview:self.hostInfoView];
    UIImageView *host_Icon = [[UIImageView alloc] init];
    host_Icon.frame = CGRectMake(0,0,40,40);
    host_Icon.layer.cornerRadius = 20;
    host_Icon.layer.masksToBounds = 1;
    NSDictionary *hostInfo = [XTool GetDefaultInfo:HOST_USER];
    NSURL *host_icons = [NSURL URLWithString:hostInfo[@"avatar"]];
    [host_Icon sd_setImageWithURL:host_icons placeholderImage:[UIImage imageNamed:@"logo"]];
    host_Icon.contentMode = UIViewContentModeScaleAspectFill;
    // host_Icon.image = [UIImage imageNamed:@"hosts"];
    [_hostInfoView addSubview:host_Icon];
    
    NSString *nick_Str = hostInfo[@"nickname"];
    CGFloat widths  =[XTool calculateRowWidth:nick_Str andHeight:15 andSize:12];
    if(widths>70){
        widths =70;
    }
    UILabel *nick_Lab = [[UILabel alloc] init];
    nick_Lab.frame = CGRectMake(45,5,widths,15);
    nick_Lab.text = hostInfo[@"nickname"];
    nick_Lab.font = [UIFont fontWithName:@"PingFang-SC-Medium" size:12];
    nick_Lab.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    nick_Lab.textAlignment = NSTextAlignmentLeft;
    nick_Lab.alpha = 1;
    nick_Lab.numberOfLines = 0;
    [_hostInfoView addSubview:nick_Lab];
    
    UIImageView *level_Img = [[UIImageView alloc]initWithFrame:CGRectMake(45+5+widths, 5, 25, 12)];
    level_Img.image = [UIImage imageNamed:@"Group 20"];
    // level_Img.contentMode = UIViewContentModeScaleAspectFit;
    [_hostInfoView addSubview:level_Img];
    
    UILabel *leve_Lab = [[UILabel alloc]initWithFrame:CGRectMake(45+3+widths, 5, 25, 12)];
    leve_Lab.text = @"10";
    leve_Lab.textColor=[UIColor whiteColor];
    leve_Lab.font = [UIFont systemFontOfSize:10];
    leve_Lab.textAlignment = NSTextAlignmentRight;
    [_hostInfoView addSubview:leve_Lab];
    
    UILabel *room_id = [[UILabel alloc] init];
    room_id.frame = CGRectMake(45,20,140,20);
    room_id.text = [NSString stringWithFormat:@"房间号：%@ 粉丝：0",hostInfo[@"id"]];
    room_id.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:11];
    room_id.textColor = [UIColor colorWithRed:255/255.0 green:255/255.0 blue:255/255.0 alpha:1];
    room_id.textAlignment = NSTextAlignmentLeft;
    room_id.alpha = 1;
    room_id.tag = 152;
    room_id.numberOfLines = 0;
    [_hostInfoView addSubview:room_id];
    
    
}
@end
